<template>
  <div class="app-container">

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="primary"
            plain
            icon="el-icon-search"
            size="mini"
            @click="handleSearch"
        >搜索
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['money:mondet:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="3" style="position: absolute; right: 35px; top: 0">
        <Page
          style="margin-right: 0px"
          :current="queryParams.pageNum"
          :page-size="queryParams.pageSize"
          :total="total"
          @on-change="pageChange"
          simple></Page>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table
      highlight-current-row
      border
      stripe
      v-loading="loading"
      :height="tableH"
      :data="mondetList"
      :header-cell-style="{'text-align':'center'}">
      <el-table-column label="#" type="index" width="40" align="center"/>
      <el-table-column label="单号" :show-overflow-tooltip="true" width="150"  align="center" prop="momZzdh" />
      <el-table-column label="客户代码" :show-overflow-tooltip="true" width="150"  align="center" prop="itmCustwldm" />
      <el-table-column label="品名规格" :show-overflow-tooltip="true"  align="center" prop="itmPmgg" />
      <el-table-column label="材料单价" :show-overflow-tooltip="true" width="150"  align="center" prop="momUnitPrice" />
      <el-table-column label="产品售价" :show-overflow-tooltip="true" width="150" align="center" prop="momSellingPrice" />
      <el-table-column label="加工费" :show-overflow-tooltip="true" width="150" align="center" prop="momProcessingFees" />
      <el-table-column label="加工工时" :show-overflow-tooltip="true" width="150" align="center" prop="momJggs" />
    </el-table>

        <!-- 查询对话框   -->
    <el-dialog :title="title"
               v-model="openSearch"
               :close-on-click-modal="false"
               draggable
               width="400px"
               append-to-body>
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
          <el-col :span="24">
                    <el-form-item label="单号" prop="momZzdh">
                      <el-input
                          v-model="queryParams.momZzdh"
                          placeholder="请输入单号"
                          clearable
                          size="small"
                          @keyup.enter.native="handleQuery"
                      />
                    </el-form-item>
                  </el-col>
        <el-col :span="24">
          <el-form-item label="综合查询" prop="itmPmgg">
            <el-input
              v-model="queryParams.itmPmgg"
              placeholder="综合查询"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item style="margin-top: 25px; display: flex;justify-content: flex-end">
            <el-button @click="cancel">取消</el-button>
            <el-button type="primary" @click="handleQuery">确认</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { listMondet,  exportMondet } from "@/api/money/mondet";

export default {
  name: "Mondet",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      tableH: document.body.clientHeight - 300,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      openSearch:false,
      // 总条数
      total: 0,
      // 制造单号金额数据表格数据
      mondetList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: document.body.clientHeight > 900 ? 25 : 17,
        momZzdh: null,
        itmPmgg:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询制造单号金额数据列表 */
    getList() {
      this.loading = true;
      listMondet(this.queryParams).then(response => {
        this.mondetList = response.rows
        this.total = response.total;
        this.loading = false;
      });
    },
    pageChange(page) {
      this.queryParams.pageNum = page
      this.getList()
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openSearch = false
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        momMoeid: null,
        momUnitPrice: null,
        momSellingPrice: null,
        momProcessingFees: null,
        momJggs: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.mondetList = [];
      this.getList();
      this.openSearch = false
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    handleSearch() {
      this.reset()
      this.title = "查询制造单号金额数据"
      this.openSearch = true
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有制造单号金额数据数据项?', "确认导出", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportMondet(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>

<style lang="scss" scoped>

</style>
